//
//  GameWindow.cpp
//  Editor
//
//  Created by Jeppe Nielsen on 11/17/14.
//  Copyright (c) 2014 Jeppe Nielsen. All rights reserved.
//

#include "GameWindow.hpp"
#include <QtWidgets/QtWidgets>
#include "Project.hpp"

std::string GameWindow::GetName() { return "Game"; }

void GameWindow::OnCreate() {
    
    opengl = new OpenGLWidget(window);
    
    window->setWidget(opengl);
    
    context->CurrentProject.Changed += event_handler(this, &GameWindow::ProjectChanged);
}

void GameWindow::ProjectChanged(Nano::Property<Context *, Project *>::EventData d) {
    if (d.Old) {
        d.Old->OnUpdate -= event_handler(this, &GameWindow::Update);
    }
    
    if (d.Current) {
        d.Current->OnUpdate += event_handler(this, &GameWindow::Update);
    }
}


void GameWindow::Update(float dt) {
    opengl->Render();
}